package TestPojoNetty;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import org.jboss.netty.bootstrap.Bootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

public class PojoServer {
	/**
	 * 
	 */
	public static void run() {
		// TODO Auto-generated method stub
		ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
		ServerBootstrap bootstrap = new ServerBootstrap(factory);
		
		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {		
			@Override
			public ChannelPipeline getPipeline() throws Exception {
				// TODO Auto-generated method stub
				ChannelPipeline pipeline = Channels.pipeline();
				pipeline.addLast("encoding", new EncodingHandle());
				pipeline.addLast("decoding", new DecodingHandle());
				pipeline.addLast("handle", new ServerHandle());	
				return pipeline;
			}
		});
		bootstrap.setOption("child.tcpNoDelay", true);    
        bootstrap.setOption("child.keepAlive", true);    
            
        bootstrap.bind(new InetSocketAddress(8080));
	}
	
	public static void main(String[] args) {
		run();
	}
}
